/**
 * 路由定义
 * 作者：夏冬琦 2021-08
 */


const routes = [

    //访问路由“/”,自动重定向到"/home"
    {
        path: '/',
        redirect: '/home'
    },   
    {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/home.vue'),
        meta:{
            sub:false,
            navName:'主页'
        },
        children:[
            //用户管理
            {
                path:'/security/user',
                name:'SecurityUser',
                component: () => import('@/views/security/user/index.vue'),
                meta:{
                    sub:true,
                    navName:'用户管理'
                }
            }
        ]       
    },
    {
        path: '/login',
        name: "Login",
        component: () => import('@/views/login.vue')
    },
    
    {
        path: '/404',
        name: "NotFound",
        component: () => import('@/views/404.vue')
    },
    

];

// 判断路由是否存在
const existsRoute_inner = (path,theRoutes)=>{
    for (let i = 0; i < theRoutes.length; i++) {
        const r = theRoutes[i];
        if (r.path == path) {
            return true;
        }
        if (r.children && r.children.length) {
            const existsInChildren = existsRoute_inner(path,r.children);
            if(existsInChildren)return true;            
        }
    }
    return false;
};

export const existsRoute = (path) => {

    return existsRoute_inner(path,routes);

    // for (let i = 0; i < routes.length; i++) {
    //     const r = routes[i];
    //     if (r.path == path) {
    //         return true;
    //     }
    //     if (r.children && r.children.length) {
    //         for (let k = 0; k < r.children.length; k++) {
    //             const sr = r.children[k];
    //             if (sr.path == path) {
    //                 return true;
    //             }
    //         }
    //     }
    // }
    // return false;
};

export default routes;